package chapter6;

/**
 * 匿名内部类的使用，匿名内部必须继承一个父类或者实现一个接口
 */
interface ProductInter {
    public double getPrice();
    public String getName();
}

public class AnonymousTest {
    public void test(ProductInter productInter) {
        System.out.println("购买了一个:" + productInter.getName() + "，花掉了" + productInter.getPrice());
    }

    public static void main(String[] args) {
        AnonymousTest anonymousTest = new AnonymousTest();
        anonymousTest.test(new ProductInter() {
            @Override
            public double getPrice() {
                return 567.8;
            }

            @Override
            public String getName() {
                return "AGP显卡";
            }
        });
    }
}
